package cn.tedu.mall.seckill.timer.config;

import cn.tedu.mall.seckill.timer.job.SeckillInitialJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    //向Spring容器中保存JobDetail
    @Bean
    public JobDetail initJobDetail(){
        return JobBuilder.newJob(SeckillInitialJob.class)
                .withIdentity("initJobDetail")
                .storeDurably()
                .build();
    }
    //向Spring容器保存Trigger对象
    @Bean
    public Trigger initTrigger(){
        CronScheduleBuilder cron = CronScheduleBuilder.cronSchedule("0 0/1 * * * ?" );
        return TriggerBuilder.newTrigger()
                .forJob(initJobDetail())
                .withSchedule(cron)
                .build();
    }
}
